﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS.Module
{
    public partial class ucBreadcrumb : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath;
            url = url.Substring(1, url.Length - 1);
            string url1 = url.Replace(".", "/");
            string Module = url1.Substring(0, url1.IndexOf("/"));
            if (Module == "SanPham")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["pt"]))
                {
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>";
                    int loaiSanPhamID = int.Parse(Request.QueryString["pt"]);
                    cmsLoaiSanPhamDO objLoaiSanPham = new cmsLoaiSanPhamDO();
                    cmsLoaiSanPhamBL loaiSanPhamBL = new cmsLoaiSanPhamBL();
                    objLoaiSanPham.LoaiSanPhamID = loaiSanPhamID;
                    objLoaiSanPham = loaiSanPhamBL.Select(objLoaiSanPham);
                    lblTitle.Text += " » <a href='/SanPham/pt/" + objLoaiSanPham.LoaiSanPhamID + "/" + FriendlyUrl(objLoaiSanPham.TenLoaiSanPham) + "' title ='" + objLoaiSanPham.TenLoaiSanPham + "'>" + objLoaiSanPham.TenLoaiSanPham + "</a>";
                }
                else if (Request.QueryString["NhanHieu"] != null)
                {
                    int NhanHieuID = int.Parse(Request.QueryString["NhanHieu"]);
                    string NhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » ";
                    lblTitle.Text += "<a href='/SanPham/NhanHieu/" + NhanHieuID + "/" + FriendlyUrl(NhanHieu) + "'" + ">" + NhanHieu + "</a>";
                }
                else if (Request.QueryString["LoaiSP"] != null)
                {
                    int LoaiSP = int.Parse(Request.QueryString["LoaiSP"]);
                    string title = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSP }).TenLoaiSanPham;
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » " + "<a href='/SanPham/LoaiSP/" + LoaiSP + "/" + FriendlyUrl(title) + "'" + ">" + title + "</a>";
                }
                else if (Request.QueryString["Filter"] != null)
                {
                    int LoaiSPID = int.Parse(Session["LoaiSP"].ToString());
                    int NhanHieuID = int.Parse(Request.QueryString["Filter"].ToString());
                    string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).TenLoaiSanPham;
                    string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » " + "<a href='/SanPham/Filter/" + NhanHieuID + "/" + FriendlyUrl(titleNhanHieu) + "'" + ">" + titleLoaiSP + " - " + titleNhanHieu + "</a>";
                }
                else if (Request.QueryString["FilterDM"] != null)
                {
                    int LoaiSPID = int.Parse(Request.QueryString["FilterDM"]);
                    int NhanHieuID = int.Parse(Session["NhanHieu"].ToString());
                    string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).TenLoaiSanPham;
                    string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » " + "<a href='/SanPham/FilterDM/" + LoaiSPID + "/" + FriendlyUrl(titleLoaiSP) + "'" + ">" + titleNhanHieu + " - " + titleLoaiSP + "</a>";
                }

                else
                {
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>";
                }
            }
            else if (Module.Equals("Search-tt") || Module.Equals("Search-sp"))
            {
                lblTitle.Text = "<a href='/Search/" + Request.QueryString["ID"].ToString() + "/Tim-Kiem.aspx'> Tìm kiếm \"" + Request.QueryString["ID"].ToString() + "\"</a>";
            }
            else if (Module == "About")
            {
                if (Request.QueryString["ID"] != null)
                {
                    int ID = int.Parse(Request.QueryString["ID"]);
                    string title = new cmsCategoryBL().Select(new cmsCategoryDO { CategoryID = ID }).Title;

                    lblTitle.Text = "<a href='/About/" + ID + "/" + FriendlyUrl(title) + "'>" + title + "</a>";
                }
            }

            else if (Module.Equals("Category"))
            {
                if (Request.QueryString["ID"] != null)
                {
                    int categoryID = int.Parse(Request.QueryString["ID"]);
                    cmsCategoryDO objCate = new cmsCategoryDO();
                    cmsCategoryBL cateBL = new cmsCategoryBL();
                    objCate.CategoryID = categoryID;
                    objCate = cateBL.Select(objCate);
                    lblTitle.Text += "<a href='/Category/" + objCate.CategoryID + "/" + FriendlyUrl(objCate.Title) + "' title ='" + objCate.Title + "'>" + objCate.Title + "</a>";

                }
                else
                {
                    lblTitle.Text = "<a href='/Category/4/Tin-Tuc.aspx'>Tin tức</a>";
                }
            }
            else if (Module == "SanPhamChiTiet")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    int sanPhamID = int.Parse(Request.QueryString["ID"]);
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>";

                    int loaiSanPhamID = new cmsSanPhamBL().Select(new cmsSanPhamDO { SanPhamID = sanPhamID }).LoaiSanPhamID;

                    cmsLoaiSanPhamDO objLoaiSanPham = new cmsLoaiSanPhamDO();
                    cmsLoaiSanPhamBL loaiSanPhamBL = new cmsLoaiSanPhamBL();
                    objLoaiSanPham.LoaiSanPhamID = loaiSanPhamID;
                    objLoaiSanPham = loaiSanPhamBL.Select(objLoaiSanPham);
                    lblTitle.Text += " » <a href='/SanPham/pt/" + objLoaiSanPham.LoaiSanPhamID + "/" + FriendlyUrl(objLoaiSanPham.TenLoaiSanPham) + "' title ='" + objLoaiSanPham.TenLoaiSanPham + "'>" + objLoaiSanPham.TenLoaiSanPham + "</a>";
                }
            }
            else if (Module.Equals("Article"))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
                {
                    int categoryID = new cmsArticleBL().Select(new cmsArticleDO{ArticleID =  int.Parse(Request.QueryString["ID"])}).CategoryID;
                    cmsCategoryDO objCate = new cmsCategoryDO();
                    cmsCategoryBL cateBL = new cmsCategoryBL();
                    objCate.CategoryID = categoryID;
                    objCate = cateBL.Select(objCate);
                    lblTitle.Text += "<a href='/Category/" + objCate.CategoryID + "/" + FriendlyUrl(objCate.Title) + "' title ='" + objCate.Title + "'>" + objCate.Title + "</a>";
                }
            }
            else if (Module == "Contact")
                lblTitle.Text = "<a href='/Contact.aspx'> Liên Hệ</a>";
            else if (Module == "ThongTin")
                lblTitle.Text = "<a href='/ThongTin/" + Session["IDDN"].ToString() + "/Thong-tin-ca-nhan.aspx'> Thông tin cá nhân</a>";
            else if (Module == "DoiMK")
                lblTitle.Text = "<a href='/DoiMK.aspx'>Đổi mật khẩu</a>";
            else if (Module == "GioHang")
            {
                lblTitle.Text = "<a href='/GioHang.aspx'> Giỏ hàng </a>";
            }
            else if (Module == "Register")
            {
                lblTitle.Text = "<a href='/Register.aspx'> Đăng ký thành viên </a>";
            }
            else if (Module == "ThanhToan")
            {
                lblTitle.Text = "<a href='/ThanhToan.aspx'> Gửi đơn hàng </a>";
            }
            else if (Module == "BaoGia")
            {
                lblTitle.Text = "<a href='/BaoGia.aspx'> Tải Báo giá </a>";
            }
            else
            {
                lblTitle.Text = "<a href='/" + Module + ".aspx'>" + Module + " </a>";
            }
        }

        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}